from flask import Flask,request
from flask import render_template
# 服务端的中央等级中心
# 1.url： *url的相对路径（终结点） *request的methods【GET】【POST】
# 2.view function视图函数， *模板渲染【HTML+CSS】， *处理数据
# 3.return：返回到templates（放HTML的内容）文件夹中对应的HTML文件


app = Flask(__name__)

# 1，,现实资源【GET】
@app.route('/')
def hello_world():
    return render_template('hello.html')

# 2.处理数据后，显示资源【POST】
@app.route('/index')
def index():
    return render_template('index.html')

@app.route('/vowels')
def vowels():
    return render_template('vowels.html')


@app.route('/ShoppingCart')
def ShoppingCart():
    return render_template('ShoppingCart.html')

@app.route('/tree')
def tree():
    return render_template('tree.html')


@app.route('/result',methods=["POST"])
def result():
    # 链接成功 python中的变量去接收html中input的变量内容
    py_firstname = request.form['firstname']
    py_lastname = request.form['lastname']
    py_fullname = py_firstname.title() + ' ' + py_lastname.title()


    # 新加渲染模板规则：{{}}
    return render_template('result.html',
                           fullname = py_fullname,
                          )

@app.route('/vowelsresult',methods=["POST"])
def vowelsresult():
    py_word = request.form ['word']
    py_vowels =request.form['vowels']
    py_found = {}
    for i in py_word:
        if i in py_vowels:
            py_found.setdefault(i,0)
            py_found[i]+=1
    return render_template('vowelsresult.html',
                found = py_found)

@app.route('/ShoppingCart_result',methods=["POST"])
def ShoppingCart_result():
    py_Alipay = request.form['Alipay']

    return render_template('ShoppingCart_result.html',
                           alipay=py_Alipay,
                           )